using Unity.VisualScripting;

namespace LS.UGFUnits
{
    public class UnloadAllScenes: SceneUnit
    {
        protected override ControlOutput In(Flow flow)
        {
            string[] assetNames = Target?.GetLoadedSceneAssetNames();
            if (assetNames != null && assetNames.Length > 0)
            {
                for (int i = 0; i < assetNames.Length; i++)
                {
                    if (!(Target?.SceneIsLoading(assetNames[i]) ?? false) && !(Target?.SceneIsUnloading(assetNames[i])?? false))
                    {
                        Target?.UnloadScene(assetNames[i]);
                    }
                }
            }
            return base.In(flow);
        }
    }
}